<template>
<div>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="优惠券名称:">
      {{form.name}}
    </el-form-item>
    <el-form-item label="图片:">
      <el-image :src="form.image"></el-image>
    </el-form-item>
    <el-form-item label="折扣金额">
      {{form.price}}
    </el-form-item>
    <el-form-item label="开始时间">
     {{form.startDate}}
    </el-form-item>
     <el-form-item label="结束时间">
     {{form.endDate}}
    </el-form-item>
  <el-form-item label="最低金额">
  {{form.minChase}}
    </el-form-item>
  <el-form-item label="最高金额">
   {{form.maxChase}}
    </el-form-item>
  <el-form-item label="发行数量">
{{form.quantity}}
    </el-form-item>
  <el-form-item label="状态">
{{form.status}}
    </el-form-item>
  <el-form-item label="备注">
 {{form.notes}}
    </el-form-item>
 <el-form-item label="发出时间">
{{form.createTime}}
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="qiang()">抢单</el-button>
      <el-button @click="to">返回</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
export default {
  name: "DetailsView",
  data() {
    return{
      form:{}
    }
  },methods:{
    qiang(){
      this.axios.post("coupon/buy?couponId="+sessionStorage.getItem("id")).then(r=>{
        if(r.data.code==200) {
          this.$message.success("抢单成功");
        }else {
          this.$message.error("抢单失败");
        }
      })

    },
    to(){
      this.$router.push("/coupon")
    },
    list(){
      this.axios.post("coupon/getById?id="+sessionStorage.getItem("id")).then(r=>{
        this.form=r.data.data;
        if(this.form.status==0){
        this.form.status="有效"
      }else if(this.form.status==1){
          this.form.status="无效"
      }else if(this.form.status==2){
        this.form.status="已过期"
      }

      })
    }
  }, created() {
  this.list();
  }
}
</script>

<style scoped>

</style>
